package juc;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ThreadPoolExample4 {
    public static void main(String[] args) {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(5);
//        for (int i = 0; i < 10; i++) {
//            int index = i;
//            executorService.execute(()-> System.out.println("task:" + index));
//        }
//        executorService.schedule(() -> System.out.println("schedule run"), 3, TimeUnit.SECONDS);
        executorService.scheduleAtFixedRate(() -> System.out.println("scheduleAtFixedRate run"),
                1, 3, TimeUnit.SECONDS);
//        executorService.shutdown();
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("TimeTask Run");
            }
        }, new Date(), 2 * 1000);
    }
}
